<?php

namespace App\Http\Controllers\Frontend\V10\Update;

use App\Constants\RedisKey;
use App\Models\AppUpdateInfo;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;

class UpdateController extends Controller {
    //
    /**
     * app版本信息
     * @param Request $request
     * @return mixed
     * @author luwei
     * @date 2019-01-13 10:20
     */
    public function index(Request $request) {
        $key = RedisKey::APP_UPDATE_INFO;
        $data = Redis::get($key);
        $return = json_decode($data,true);
        if(!$return){
            $data   = AppUpdateInfo::byStatus(AppUpdateInfo::STATUS_USE)->firstOrFail();
            $return = [
                'id'              => $data->id,
                'title'           => $data->title,
                'app_update_text' => $data->app_update_text,
                'ios_pkg_url'     => $data->ios_pkg_url,
                'version'         => $data->version,
                'app_update_time' => $data->app_update_time->format('Y-m-d'),
                'install_pkg_url' => $data->install_pkg_url,
                'is_force'        => $data->is_force
            ];
            Redis::set($key,json_encode($return,JSON_UNESCAPED_UNICODE));
        }
        return success($return);
    }
}
